package com.huzz.config;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.Environment;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.oas.annotations.EnableOpenApi;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

/**
 * @Name swagger配置类
 * @Description 描述
 * @Author 童年的纸飞机
 * @Since 2023-08-2023/8/2 08:50
 */
@Configuration
@EnableOpenApi
public class SwaggerConfig {

    @Autowired
    private Environment env;

    @Value("${swagger.enable}")
    private Boolean enable;

    @Bean
    public Docket createRestApi() {
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo())
                .enable(enable)
                .select()
                // 要扫描的API(Controller)基础包          .apis(RequestHandlerSelectors.basePackage("com.ion.web.controller"))
                // 要扫描的API(Controller)全局-(就是可以扫描所有的带有api注解的包并生成文档)
                // .apis(RequestHandlerSelectors.any())
                .paths(PathSelectors.any())
                .build();
    }

    private ApiInfo apiInfo() {
        return new ApiInfoBuilder()
                .title("springboot利用swagger构建api文档")
                .description("简单优雅的restfun风格，https://www.xxxxxx.com")
                .termsOfServiceUrl("https://www.xxxxxx.com")
                .version("1.0")
                .build();
    }

}
